#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os,sys,re
from wwpy.dmc.dps.DMS import DMS
from wwpy.dmc.dps.Bean import Field,Src,Hih
from wwpy.util.Wrapper import looper
from wwpy.util.Time import Time

@looper('DAY')
def main(date):
    mini_date=date
    date=Time.date_format(date)
    dms=DMS(
        select=[
            Field(name='date',value=mini_date,type='date'),
            Field(name='user',value='p.user_id',type='bigint(20)'),
            Field(name='product',value='o.product_id',type='bigint(20)'),
            Field(name='city',value='p.city',type='varchar(30)'),
            Field(name='post_count',value='p.post_count',func='sum'),
        ],
        from_=[
               Src(name='p',value="SELECT user_id,city,post_count FROM db_58_ib.post_info WHERE stat_date='%s' AND post_count>0 AND cate2='二手汽车转让'" % (date),fields=('user_id','city','post_count')),
               Src(name='o',value="SELECT user_id,product_id FROM db_58_stat.order_info WHERE pay_amount>0 AND product_type=10 AND DATE(service_begin_time)<='%s' AND DATE(service_end_time)>='%s'" % (date,date),fields=('user_id','product_id')),
               ],
        join=[
              Hih(src='o',on='p.user_id=o.user_id'),
              ],
        group=['date','user','product','city'],
    )
    dms.sep(',')
    dms.file('esc_post_%s.txt' % mini_date)
    #dms.store()
    dms.load('esc_post')
    
if __name__ == '__main__':
    main()
    
